<?php

/**
 * \file
 * Classe `Time`.
 */

namespace pilar\SimpleFormMembers /* \cond */ ; /* \endcond */
{

/**
 * Membre d'heure de la journée.
 *
 * \since 10/02/2009
 * \author Salim TALEB <salim.taleb@ecl2010.ec-lyon.fr>
 */
class Time extends \pilar\Forms\Member {

protected function loadDefaultParams() {
 parent::loadDefaultParams();

 $this->params->define(array(
  'withSeconds' => false
 ));
}


protected function initialize() {
 parent::initialize();
 
 $this->joinField('H'); // Heure.
 $this->joinField('I'); // Minutes.
 if($this->get('withSeconds')) $this->joinField('S'); // Secondes.
}


public function guiDomNode($domDoc) {
 $domGui = $domDoc->createElement('gui');

 $domHour = $domDoc->createElement('input');
 $domHour->setAttribute('id', $this->globalId('H'));
 $domHour->setAttribute('name', $this->globalId('H'));
 $domHour->setAttribute('size', 2);
 $domHour->setAttribute('maxlength', 2);
 $domHour->setAttribute('title', $this->get('label').' (heure)');
 $domGui->appendChild($domHour);

 $domGui->appendChild($domDoc->createTextNode(' : '));

 $domMinute = $domDoc->createElement('input');
 $domMinute->setAttribute('id', $this->globalId('I'));
 $domMinute->setAttribute('name', $this->globalId('I'));
 $domMinute->setAttribute('size', 2);
 $domMinute->setAttribute('maxlength', 2);
 $domMinute->setAttribute('title', $this->get('label').' (minutes)');
 $domGui->appendChild($domMinute);

 if($this->get('withSeconds')) {
  $domGui->appendChild($domDoc->createTextNode(' : '));

  $domSecond = $domDoc->createElement('input');
  $domSecond->setAttribute('id', $this->globalId('S'));
  $domSecond->setAttribute('name', $this->globalId('S'));
  $domSecond->setAttribute('size', 2);
  $domSecond->setAttribute('maxlength', 2);
  $domSecond->setAttribute('title', $this->get('label').' (secondes)');
  $domGui->appendChild($domSecond);
 }

 return $domGui;
}


protected function outputGuiController() { ?>
<?php foreach($this->fieldNames() as $f) { ?>
<?php  if($this->value($f) != '') { ?>
$('#<?php echo $this->globalId($f) ?>').val('<?php echo $this->value($f) ?>');
<?php  } ?>
<?php  if($this->status() == 'invalid') { ?>
$('#<?php echo $this->globalId($f) ?>').addClass('invalid');
<?php  } ?>
<?php } ?>
<?php
}

} // Class.

} // Namespace.

?>
